
_realname=netcdf-cxx
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.3.1
pkgrel=3
pkgdesc="NetCDF C++ bindings (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/Unidata/netcdf-cxx4/"
license=(custom)
depends=(
  "${MINGW_PACKAGE_PREFIX}-netcdf>=4.6.0"
  'sed'     # for ncxx4-config
  )
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-cc"
  )
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        '0001-netcdf-cxx-4.3.1-examples-fix-plugin-name-on-MINGW32-64-and-CLANG32-64.patch')
sha256sums=('e3fe3d2ec06c1c2772555bf1208d220aab5fee186d04bd265219b0bc7a978edc'
            'c09052c393f0eee15a0e58af9cc3fa9d42c4d1b9b5076fb84bafa2eb14a2a1f3')

prepare() {
  cd "${_realname}${pkgver/.*/}-${pkgver}"

  patch -p1 < '../0001-netcdf-cxx-4.3.1-examples-fix-plugin-name-on-MINGW32-64-and-CLANG32-64.patch'

  autoreconf -vfi
}

build() {
  mkdir -p "build-${_realname}-${pkgver}-${MSYSTEM}"
  cd "build-${_realname}-${pkgver}-${MSYSTEM}"
  ../${_realname}${pkgver/.*/}-${pkgver}/configure -C \
    --prefix="${MINGW_PREFIX}"

  # file VERSION (generated by configure) confuses those
  # CLANG32/64 header files which #include <version>
  mv -f VERSION .VERSION

  make libh5bzip2_la_LIBADD=-lhdf5 LIBS=-lnetcdf
}

check() {
  make -j1 check -C "build-${_realname}-${pkgver}-${MSYSTEM}"
}

package() {
  make install DESTDIR="${pkgdir}" -C "build-${_realname}-${pkgver}-${MSYSTEM}"
  install -Dm644 "${_realname}${pkgver/.*/}-${pkgver}"/COPYRIGHT -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/"
}
